<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>投保管理</title>
    <style type="text/css">

        #insureDiv,#plcDiv{
            display: block!important;
        }
    </style>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div id="insureDiv" class="sqPanel" style="margin-bottom: 0;">
        <div class="sqPanel_head">
            <table class="table_full">
                <tr>
                    <td><b>待投保列表 </b></td>
                </tr>
            </table>
        </div>
        <div class="sqPanel_body">
            <div id="ligergrid1" class="sq-grid"></div>
        </div>
    </div>

    <div id="plcDiv" class="sqPanel" style="margin-bottom: 0;">
        <div class="sqPanel_head">
            <table class="table_full">
                <tr>
                    <td><b>保单列表</b><span id="arAmt"/></td>
                </tr>
            </table>
        </div>
        <div class="sqPanel_body">
            <div id="plcGrid" class="sq-grid"></div>
        </div>
    </div>
</div>

<script type="text/javascript">
    var grid = null,callback = null,plcGrid = null;
    $(function () {
        var operateInsPlc = '${operateInsPlc}';
        grid = $("#ligergrid1").ligerGrid({
            url: '<%=path%>/insurance/insInsure/searchList.do?prjId=${prjId}&payStsCd=${payStsCd}&insStsCd=10&paySchId=${paySchId}',
            method: 'get',
            columns: [
                {display: '客户名称', name: 'cstNm', width: 100, align: 'center',
                    render:function(rowdata,rowindex,value){
                        return '<a href="javascript:;" onclick="showCstDtl('+rowdata.cstId+')"><span class="gridTip" title="客户查看">'+rowdata.cstNm+'</span></a>';
                    }
                },
                {display: '支付表号', name: 'paySchNo', width: 180, align: 'center'},
                {display: '合同号', name: 'lsCntNo', width: 150, align: 'center'},
                {display: '业务类型', name: 'prjTypCdNm', width: 100, align: 'center'},
                {display: '供应商', name: 'splNm', minWidth: 120, align: 'center',
                    render:function (rowdata,rowindex,value) {
                        if(value){
                            return '<span class="gridTip" title="'+ value +'">'+ value +'</span>'
                        }
                }},
                {display: '产品名称', name: 'prdNm', width: 100, align: 'center'},
                {display: '单价', name: 'prdPrc', width: 100, align: 'center',
                    render:function(rowdata,rowindex,value){
                        return '&yen;'+FormatMoney(rowdata.prdPrc/100);
                    }
                },
                {display: '合格证号', name: 'certNo', minWidth: 100, align: 'center',
                    render:function(rowdata,rowindex,value){
                        if(value){
                            return '<a href="javascript:;" onclick="detailBtn('+rowdata.actPrdId+','+rowdata.prjPrdDtlId+')">'+rowdata.certNo+'</a>';
                        }
                    }
                },
                {display: '投保状态', name: 'insStsCdNm', width: 90, align: 'center'},
                {display:"操作",width:100,align:'left',
                    render:function (rowdata,rowindex,value) {
                        if(rowdata.insStsCd=='10'){
                            return '<a class="sq-button-hasicon" href="javascript:;" onclick="recordPlc('+rowindex+');"><i class="sqBtnIco_3"></i>录单</a>';
                        }
                    }
                }
            ],
            usePager: false,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '300',
            heightDiff: -2,
            rownumbers: true,
            allowUnSelectRow: true,
            alternatingRow: false,
            checkbox:false,
            isSingleCheck:true,
            onLoaded:function(currentData){
                if(currentData && currentData.data.total>0){
                    $("#insureDiv").show();
                }else{
                    $("#insureDiv").hide();
                }
                currentData.toggleLoading.ligerDefer(currentData, 10, [false]);
            }
        });
        grid.setHeight(100);

        plcGrid = $("#plcGrid").ligerGrid({
            url: '<%=path%>/insurance/insPlcBscInfo/searchList.do?prjId=${prjId}&payStsCd=${payStsCd}&paySchId=${paySchId}',
            method: 'get',
            columns: [
                {display: '客户名称', name: 'cstNm', minWidth: 100, align: 'center', enabledSort: false,
                    render:function(rowdata,rowindex,value){
                        return '<a href="javascript:;" onclick="showCstDtl('+rowdata.cstId+')"><span class="gridTip" title="客户查看">'+rowdata.cstNm+'</span></a>';
                    }
                },
                {display: '支付表号', name: 'paySchNo', width: 150, align: 'center'},
                {display: '保单号', name: 'plcNo', minWidth: 100, align: 'center', enabledSort: false,
                    render:function(rowdata,rowindex,value){
                        if(!value||value==null||value=='null'){
                            return '<a href="javascript:;" onclick="queryPlcDtl('+rowdata.id+')">保单</a>';
                        }
                        return '<a href="javascript:;" onclick="queryPlcDtl('+rowdata.id+')"><span class="gridTip" title="保单查看">'+rowdata.plcNo+'</span></a>';
                    }
                },
                {display: '保险种类', name: 'insTypCdNm', minWidth: 100, align: 'center', enabledSort: false},
                {display: '保险公司', name: 'insCompNm', minWidth: 100, align: 'center', enabledSort: false},
                {display: '购买方式', name: 'buyWayCdNm', minWidth: 100, align: 'center', enabledSort: false},
                {display: '被保险人', name: 'insPerNm', minWidth: 100, align: 'center', enabledSort: false},
                {display: '保费总金额', name: 'insTtlFee', minWidth: 100, align: 'right', enabledSort: false,
                    render:function(rowdata,rowid,value){
                        return '&yen;'+FormatMoney(rowdata.insTtlFee/100);
                    }
                },
                {display: '保单状态', name: 'plcStsCdNm', minWidth: 100, align: 'center', enabledSort: false},
                {display: '止保时间', name: 'plcEndTm', minWidth: 100, align: 'center', enabledSort: false,render: renderDate},
                {display: '保单性质', name: 'plcPropCdNm', minWidth: 100, align: 'center', enabledSort: false},
                {display: '操作', name: '', width: 150, align: 'center',
                    render:function(rowdata,rowid,value){
                        var a = '';
                        var b = '';
                        a = '<a class="sq-button-hasicon" href="javascript:;" onclick="modifyPlc(';
                        a += "'"+rowdata.id+"'";
                        a +=  ');"><i class="sqBtnIco_3"></i>修改</a>';
                        if(operateInsPlc=='1') {
                            b = '<a class="sq-button-hasicon" href="javascript:;" onclick="deletePlc(';
                            b += "'" + rowdata.id + "',";
                            b += "'" + rowdata.paySchId + "',";
                            b += "'" + rowdata.prjPrdDtlId + "'";
                            b += ');"><i class="sqBtnIco_3"></i>删除</a>';
                        }
                    	return a+" "+b;
                    }
                },
            ],
            usePager: false,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '300',
            heightDiff: -2,
            checkbox: false,
            rownumbers: true,
            allowUnSelectRow: true,
            alternatingRow: false,
            onLoaded:function(currentData){
                if(currentData && currentData.data.total>0){
                    $("#plcDiv").show();
                }else{
                    $("#plcDiv").hide();
                }
                currentData.toggleLoading.ligerDefer(currentData, 10, [false]);
            }
        });
        plcGrid.setHeight(100);

        $("#pageloading").hide();

        callback = function () {
            grid.reload();
            plcGrid.reload();
        };

    });

    //录单
    function recordPlc(_rowId){
        var row=grid.getRow(_rowId);
        if(!row.certNo && (row.prjTypCd != "CDDYWUL" && row.prjTypCd != "ESCJYD" && row.prjTypCd != "OWNJYD")){  // 业务类型 车抵贷业务(线下)、二手车交易贷 取消合格证 REQ-3672
            $.ligerDialog.SQalert({content: "请先录入产品合格证信息", SQ_type: "warning"});
            return;
        }
        Add_navTab("InsPlcBscInfo_"+row.prjPrdDtlId, "新增保单", '<%=path%>/insurance/insPlcBscInfo/toAddPage.do?prjPrdDtlId='+row.prjPrdDtlId+'&paySchId='+row.paySchId+'&paySchNo='+row.paySchNo+'&cstId='+row.cstId+'&prjId='
            +row.prjId+'&contNo='+row.lsCntNo, callback);
    }

    /* 修改 */
    function modifyPlc(_id){
        Add_navTab('InsPlcBscInfo_2'+_id, "修改保单", '<%=path%>/insurance/insPlcBscInfo/toModifyPage.do?id='+_id, callback);
    }

    /* 删除 */
    function deletePlc(_id,_paySchId,_prjPrdDtlId){
        if(!_id)return;
		var _ids = [];
		_ids.push(_id);
		$.ligerDialog.confirm('确定删除吗?', function (flag) {
			if(flag == false)return;
			var wait_dialog;
			$.ajax({
				type: 'post',
				dataType:'json',
				data:{ids:JSON.stringify(_ids), paySchId:_paySchId, prjPrdDtlId:_prjPrdDtlId},
				url: '<%=path%>/insurance/insPlcBscInfo/removeByIds.do',
				beforeSend: function(){
			          wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
			     },
				success:function(msg){
					wait_dialog.close();
					 if(msg.success == 1){
						 $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
						 liger.get("plcGrid").reload();
                         liger.get("ligergrid1").reload();
					 }else{
						 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
					 }
				}
			});
		});
    }

    //查询客户详情
    function showCstDtl(_cstId){
        Add_navTab("InsPlcCstBscInfo_"+_cstId, "客户信息", '<%=path%>/customer/cstbscinfo/toCustDetailPage.do?id='+_cstId, null);
    }

    //合格证详情
    function detailBtn(id,dtlId){
        Add_navTab('tab_prj_prd_veh_info_detail'+id,'合格证详情','<%=path%>/project/prjprdvehinfo/toDetailPage.do?detailFlag=true&&id='+id+'&&dtlId='+dtlId);
    }

    //查询保单详情
    function queryPlcDtl(_id){
        Add_navTab('InsPlcBscInfo_DTL_'+_id, "保单详情", '<%=path%>/insurance/insPlcBscInfo/toDetailPage.do?id='+_id, null);
    }

    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        }
        return dateStr;
    }

</script>

</body>
</html>
